const db = require("../utils/db");

// 患者-获取患者列表
exports.patientListGet = async (params) => {
    return new Promise(((resolve, reject) => {
        let sql = '';
        if (params.p_name) {
            sql = `select * from patient where p_name like '%${params.p_name}%' and p_hospital = ${params.p_hospital}`
        } else {
            sql = `select * from patient where p_hospital = ${params.p_hospital}`
        }
        db.query(sql).then(res => {
            console.log(res, "patientListGet sql查询成功结果")
            let result = {};
            result.list = res.slice((params.pageIndex - 1) * (params.pageSize), (params.pageIndex - 1) * (params.pageSize) + params.pageSize);
            result.total = res.length;
            result.pageIndex = params.pageIndex;
            result.pageSize = params.pageSize;
            resolve(result);
        }).catch(error => {
            console.log(error, "patientListGet sql查询失败结果")
            reject(error)

        })
    }))
}